Código fuente de 'Divide en bytes.asp'

<html>
<head>
<title>Divide en bytes - Códigos asp, programacion asp, descargas asp, rutinas asp</title>
</head>
<body style="font-family: Arial; font-size: 9pt">

<center><b><font face="Arial" size="3">Divide en bytes</font></b></center><br>
Divide en bytes igual que la función split() lo hace con las cadenas de texto.


    <% 
    Private function SplitBytes(byval bytesIn, bytesDelimiter) 
    ''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''
    ' Author : Mark Davis - dkram@iprimus.com.au
    ' Inputs : bytesIn 	: The bytes that are to be parsed
    ' bytesDelimiter	: The delimiting bytes 
    '     
    '
    'Returns:
    '	An array of bytes
    ''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''
    	Dim vntCurrentPosition, vntArrayIndex, vntDelimitPosition 
    	Dim arrayParsedBytes() 
    	vntArrayIndex = 0
    	Redim arrayParsedBytes(vntArrayIndex)
    	
    	if InstrB(bytesIn,vntDelimiter) > 0 Then
    	
    		vntCurrentPosition = InstrB(bytesIn,bytesDelimiter)
    		
    		Do until vntCurrentPosition < 1
    			if InstrB(bytesIn,bytesDelimiter) > 0 Then
    				
    				ReDim Preserve arrayParsedBytes(vntArrayIndex)
    				vntDelimitPosition = InstrB(1,bytesIn,bytesDelimiter,0)
    	
    				arrayParsedBytes(vntArrayIndex) = leftb(bytesIn,vntDelimitposition-1)
    				bytesIn = midb(bytesIn, vntDelimitposition + lenB(bytesDelimiter),lenb(bytesIn)-LenB(bytesDelimiter))
    				vntCurrentPosition = InstrB(bytesIn,bytesDelimiter)
    				vntArrayIndex = vntArrayIndex+1
    			End if
    		Loop
    		' Get remaining portion
    		
    		ReDim Preserve arrayParsedBytes((vntArrayIndex))
    		arrayParsedBytes(vntArrayIndex) = bytesIn
    	Else
    		arrayParsedBytes(vntArrayIndex) = bytesIn
    	End if
    	SplitBytes = arrayParsedBytes
    End function
    ''''''''''''''''''''''''''''''''''''''''
    ''
    ' Example
    	'vntbytes = "Hello World", vntDelimit = space character
    	vntBytes = chrb(72) & chrb(101) & chrb(108) & chrb(108) & chrb(111) & _
    	 	 chrb(32) & chrb(87) & chrb(111) & chrb(114) & chrb(108) & chrb(100) 
    	vntDelimit = chrb(32)
    	
    	arrayProcessedBytes = SplitBytes(vntBytes,vntDelimit)
    	numOfSplits = ubound(arrayProcessedBytes)
    	
    	response.write "<BR><br><b>Ejemplo:</b><br>"
    	response.write "Bytes para ser divididos: "
    	response.binarywrite vntBytes
    
    	For i = 0 To numOfSplits
    		response.write "<BR>"
    		response.write i & " "
    		response.binarywrite arrayProcessedBytes(i)
    		
    	Next
    %>
 
    </BODY></HTML>